package com.ll.domain.user.event.consumer;

import com.ll.app.api.req.UpdateStatusPkReqDTO;
import com.ll.domain.pk.dto.PkDTO;
import com.ll.domain.pk.enums.PkStatusEnum;
import com.ll.domain.pk.event.producer.AddPkEvent;
import com.ll.domain.pk.event.producer.UpdateStatusPkEvent;
import com.ll.domain.user.base.UserBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * pk 修改状态添加
 * @author WuHen
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class UpdateStatusPkEventToUserListener implements ApplicationListener<UpdateStatusPkEvent> {

    private final UserBaseService userBaseService;

    private final Integer JX_INTEGRAL = -5;
    @Async
    @Override
    public void onApplicationEvent(UpdateStatusPkEvent updateStatusPkEvent) {
        PkDTO pkDTO = updateStatusPkEvent.getPkDTO();
        log.info("接收到 修改PK状态信息 事件  id ：{}", pkDTO.getId());

        if(pkDTO.getStatus() == PkStatusEnum.已拒绝){
            userBaseService.addIntegral(pkDTO.getTargetId(), JX_INTEGRAL);
        }

        log.info("接收到 修改PK状态信息 事件  id ：{} 处理成功", pkDTO.getId());
    }
}
